package utils

import "reflect"

type FArray []string

func (f_arr *FArray) Write(p []byte) (n int, err error) {
	return 0, nil
}

func (a FArray) Search(value string) int {
	if len(a) == 0 {
		return -1
	}
	result := -1
	for index, v := range a {
		if v == value {
			result = index
			break
		}
	}
	return result
}

// 查找字符是否在数组中
func InArray(obj interface{}, target interface{}) bool {
	targetValue := reflect.ValueOf(target)
	switch reflect.TypeOf(target).Kind() {
	case reflect.Slice, reflect.Array:
		for i := 0; i < targetValue.Len(); i++ {
			if targetValue.Index(i).Interface() == obj {
				return true
			}
		}
	case reflect.Map:
		if targetValue.MapIndex(reflect.ValueOf(obj)).IsValid() {
			return true
		}
	}

	return false
}
